<?php
require_once 'Service/Condition.php';

/**
 * Comparison condition.
 *
 * @author baziak
 */
class Service_Condition_ZendDb_Comparison extends Service_Condition
{
    protected $_operator = '';

    public function __construct($params) {
        if (isset($params['operator'])) {
            $this->_operator = $params['operator'];
        }
        parent::__construct($params);
    }

    public function __toString()
    {
        $db = $this->getDataSource()->getAdapter();

        $field = $db->quoteIdentifier($this->_params['field']);

        if (isset($this->_params['value'])) {
            $value = $db->quote($this->_params['value']);
        } else {
            $value = $db->quoteIdentifier($this->_params['field2']);
        }

        return $field .' '. $this->_operator .' '. $value;
    }
}
